package com.ruoyi.hospital.controller.order;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.order.ShopAfterAddress;
import com.ruoyi.hospital.service.order.IShopAfterAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 回寄地址Controller
 * 
 * @author wendao
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/hospital/address")
public class ShopAfterAddressController extends BaseController
{
    @Autowired
    private IShopAfterAddressService shopAfterAddressService;

    /**
     * 查询回寄地址列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopAfterAddress shopAfterAddress)
    {
        startPage();
        List<ShopAfterAddress> list = shopAfterAddressService.selectShopAfterAddressList(shopAfterAddress);
        return getDataTable(list);
    }

    /**
     * 导出回寄地址列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:export')")
    @Log(title = "回寄地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopAfterAddress shopAfterAddress)
    {
        List<ShopAfterAddress> list = shopAfterAddressService.selectShopAfterAddressList(shopAfterAddress);
        ExcelUtil<ShopAfterAddress> util = new ExcelUtil<ShopAfterAddress>(ShopAfterAddress.class);
        util.exportExcel(response, list, "回寄地址数据");
    }

    /**
     * 获取回寄地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(shopAfterAddressService.selectShopAfterAddressById(id));
    }

    /**
     * 获取回寄地址详细信息:通过storeId 进行查询
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:query')")
    @GetMapping(value = "/selectShopAfterAddressByStoreId")
    public AjaxResult selectShopAfterAddressByStoreId()
    {
        return success(shopAfterAddressService.selectShopAfterAddressByStoreId(getStoreId()));
    }

    /**
     * 新增回寄地址
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:add')")
    @Log(title = "回寄地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopAfterAddress shopAfterAddress)
    {
        /*用于药店端的查询*/
        if(!StringUtils.isNullOrZero(getStoreId())){
            shopAfterAddress.setStoreId(getStoreId());
        }
        return toAjax(shopAfterAddressService.insertShopAfterAddress(shopAfterAddress));
    }

    /**
     * 修改回寄地址
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:edit')")
    @Log(title = "回寄地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopAfterAddress shopAfterAddress)
    {
        /*用于药店端的查询*/
        if(!StringUtils.isNullOrZero(getStoreId())){
            shopAfterAddress.setStoreId(getStoreId());
        }
        return toAjax(shopAfterAddressService.updateShopAfterAddress(shopAfterAddress));
    }

    /**
     * 删除回寄地址
     */
    @PreAuthorize("@ss.hasPermi('hospital:address:remove')")
    @Log(title = "回寄地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(shopAfterAddressService.deleteShopAfterAddressByIds(ids));
    }
}
